<?php

class cost{
    protected  $costID;
    public function __construct() {
        $args = func_get_args();
        if(count($args)==1){
           $this->setCostID($args[0]); 
        }
    }

    private function setCostID($costID){ 
        $this->costID=$costID;
    }

    public function getCost(){
        $mysqli=  connect();
        $query="
            select  *
            from    cost_list
            where   costID='".$this->costID."'
            ";
        $result=  $mysqli->query($query);
        $row=  $result->fetch_array(MYSQLI_ASSOC);
        return $row;
    }

    public function getMainCost(){
        $mysqli=  connect();
        $query="
            select      *
            from        cost_list
            where       parent is null
            order by    costID asc
            ";
        $result=  $mysqli->query($query);
        while($row=$result->fetch_array(MYSQLI_ASSOC)){
            $temp[$row["costID"]]=$row;
        }
        return $temp;
    }
    
    public function getSubCost($costID){
        $mysqli=  connect();
        $query="
            select      *
            from        cost_list
            where       parent='".$costID."'
            order by    costID asc
            ";
        $result=  $mysqli->query($query);
        while($row=$result->fetch_array(MYSQLI_ASSOC)){
            $temp[$row["costID"]]=$row;
        }
        return $temp;
    }
}
